package service;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Dao.TopDao;
import Dao.TopDaoimpl;
import entity.Str;
import entity.Top;
import entity.User;
import util.Dbconnect;

public class TopServiceimpl  implements TopService{
	TopDao td = new TopDaoimpl();
	SetService ss = new SetServiceimpl();
    /** 
     * Title: getToplist
       * Description:排行榜
       * @author 毛立新
       * @return
       * @throws Exception
     */
	@Override
	public List<Top> getToplist() throws Exception {
		// TODO Auto-generated method stub
		return td.showTop();
	}
    /**
     * Title: getcntByemail
       * Description:按email查询所背单词个数
       * @author 毛立新
       * @param email
       * @return
       * @throws Exception
     */
	@Override
	public Long getcntByemail(String email) throws Exception {
		// TODO Auto-generated method stub
		return td.showByemail(email);
	}
    /**
     * Title: getcntBybook
       * Description:查询所背诵书籍单词总数
       * @author 毛立新
       * @param book
       * @return
       * @throws Exception
     */
	@Override
	public Long getcntBybook(String email) throws Exception  {
		// TODO Auto-generated method stub
		
		return td.showBybooktype(email);
	}

	  /**
     * Title: finish
     * Description:完成度的计算
     * @author 毛立新
     */
	@Override
    public Double getFinish(String email) throws Exception{
		Long type = new TopDaoimpl().showBybooktype(email);
		Long e =  new  TopDaoimpl().showByemail(email);
		Long t = new TopDaoimpl().showBybooktype(email);
    	Double y;
    	y =  ((double)e/t);
    	return y;
    }
	
    /**
     * Title: ClearTop
       * Description:清空排行榜
       * @author 毛立新
       * @throws Exception
     */
	@Override
	public void ClearTop(String email) throws Exception {
		// TODO Auto-generated method stub
	}
    /**
     * Title: updateTop
       * Description:添加信息记录
       * @author 毛立新
       * @param booktype
       * @return
       * @throws Exception
     */
	@Override
	public int updateTop(String email) throws Exception {
		// TODO Auto-generated method stub
		return td.updateTop(email);
	}
	/**
	 * Title: Getuseremail
	   * Description:从record获得用户email
	   * @author 毛立新
	   * @return
	   * @throws Exception
	 */
	public List<String> Getuseremail()throws Exception{
		return td.Getuseremail();
	}
	/**
	 * Title: GetTop
	 * Description:获得email后向Top表输入信息
	 * @author 毛立新
	 * @return
	 * @throws Exception
	 */
	public List<Top> GetTop()throws Exception{
		List<String> ls = new TopServiceimpl().Getuseremail();
		List<Top> lt = new ArrayList<Top>();
		for(String st:ls) {
			new TopServiceimpl().updateTop(st);
		}
		return lt;
	}

	/** 
		* Title: newToplist
		* Description:排行榜的生成
		* @author 毛立新
	 */
	@Override
	public List<Top> newToplist() throws Exception {
		return td.newToplist();
	}
	
	public static void main(String[] args) throws Exception {
//		String email = "2263130346@qq.com";
//		System.out.println(new TopServiceimpl().getcntByemail(email));
//	    System.out.println(new TopServiceimpl().getcntBybook(email));	
//	    System.out.println(new TopServiceimpl().getFinish(email));
//	    System.out.println(new TopServiceimpl().updateTop(email));
//	    System.out.println(new TopServiceimpl().newToplist());
//	    System.out.println(new TopServiceimpl().Getuseremail());
//	    System.out.println(new TopServiceimpl().GetTop());
	    System.out.println(new TopServiceimpl().newToplist());
	}
	
	
}

